#!/usr/bin/env bash
count=$#
source=""
lib=""
one=""
flag=
if [[ ${count} -gt 0 ]]; then
    tmp=$1
    for f in $*; do
        if [[ -f ${f} ]];then
            if [[ ${f} =~ ".c" ]]; then
                if [[ ${f} == ${tmp} ]];then
                    one=${tmp:(-${#tmp}):(${#tmp}-2)}".out"
                    flag=1
                else
                    flag=0
                fi
                source=${source}" "${f}
                flag=1
            else
                flag=0
            fi
        elif [[ ${f} =~ "-l" || ${f} =~ "-I" ]]; then
            lib=${lib}" "${f}
            flag=1
        else
            flag=0
        fi
    done
fi

source=${source}" -o "${one}" "${lib}
echo -e "\e[0;34;1mgcc${source}\e[0m"
if [[ ${flag} -eq 1 ]]; then
    gcc ${source}
else
    echo -e '\e[0;31;1m缺少原文件\e[0m'
fi
